<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Watchers</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ev.examples.html">« 范例</a></li>
      <li style="float: right;"><a href="ev.watcher-callbacks.html">Watcher callbacks »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.ev.html">Ev</a></li>
    <li>Watchers</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ev.watchers" class="chapter">
 <h1>Watchers</h1>

 <p class="para">
  A watcher is an object that gets created to record interest in some event.
  For instance, the following code waits for
  <strong><code>STDIN</code></strong>
  to become readable:
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Wait&nbsp;until&nbsp;STDIN&nbsp;is&nbsp;readable<br /></span><span style="color: #0000BB">$w&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">EvIo</span><span style="color: #007700">(</span><span style="color: #0000BB">STDIN</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">READ</span><span style="color: #007700">,&nbsp;function&nbsp;(</span><span style="color: #0000BB">$watcher</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$revents</span><span style="color: #007700">)&nbsp;{<br />&nbsp;echo&nbsp;</span><span style="color: #DD0000">"STDIN&nbsp;is&nbsp;readable\n"</span><span style="color: #007700">;<br />});<br /></span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">run</span><span style="color: #007700">(</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">RUN_ONCE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </p>
 <p class="para">
  All the watcher constructors automatically start the watchers.
  <code class="literal">createStopped</code>
  methods create stopped watchers(e.g.
  <span class="methodname"><a href="evio.createstopped.html" class="methodname">EvIo::createStopped()</a></span>
  )
 </p>
 <p class="para">
  Note that a watcher will automatically be stopped when the watcher object is
  destroyed. Therefore, the watcher objects returned by the constructors or
  factory methods should be kept.
 </p>
 <p class="para">
  Note also that all methods changing some watcher property(
  <em class="emphasis">set</em>
  ,
  <var class="varname">priority</var>
  etc.) automatically stop and start it again if it is active, which means
  pending events get lost.
 </p>
 <p class="para">
  See also:
  <a href="ev.watcher-callbacks.html" class="link">Watcher callbacks</a>
  .
 </p>
</div>
</div></div></body></html>